import instacne from "../request";
import type { Ref } from "vue";

/* 
/role/list
根据角色名称分页获取角色列表
 */
interface IRoleAllListParams {
  keyword?: string | Ref<string>;
  pageNum?: number | Ref<number>;
  pageSize?: number | Ref<number>;
}
interface IRoleListItem {
  adminCount: number;
  createTime: string;
  description: string;
  id: number;
  name: string;
  sort: number;
  status: number;
}

interface IRoleListRes {
  list: IRoleListItem[];
  pageNum: number;
  pageSize: number;
  total: number;
  totalPage: number;
}

/* 
获取所有的角色列表信息
 */
const getRoleAllList = (data?: IRoleAllListParams): Promise<IRoleListRes> => {
  return instacne.get("/role/list", {
    params: data,
  });
};
/**
 * 添加角色
 * /role/create
 */
const addRoleList = (data: IRoleListItem): Promise<IRoleListItem> => {
  return instacne.post("/role/create", data);
};
/*
 * 修改角色信息
 * /update/{id}
 */
const roleUpdata = (data: IRoleListItem) => {
  return instacne.post(`/role/update/${data.id}`, data);
};

/*
 * 修改状态
 */
const updataStatusRole = (params: { status: number | Ref<number>; id: any }) =>
  instacne.post(`role/updateStatus/${params.id}?status=${params.status}`);

// 获取动态分配菜单数据
const AllocResource = (params: { resourceIds: any; roleId: any }) =>
  instacne.post("/home/recommendProduct/update/recommendStatus", { params });

// 给角色分配菜单
// 权限下的角色列表中的分配菜单  /mall-admin/role/allocMenu
const AllocMenu = (params: { menuIds: any; roleId: any }) =>
  instacne.post("/role/allocMenu", { params });
export {
  getRoleAllList,
  addRoleList,
  roleUpdata,
  updataStatusRole,
  AllocResource,
  AllocMenu,
};
export type { IRoleListItem };
